import 'package:casdon/core/logger/log.dart';
import 'package:casdon/core/network/business_exception.dart';
import 'package:casdon/modules/lifeCircle/data/repository/life_repository.dart';
import 'package:casdon/modules/lifeCircle/providers/life_provider.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

/// 删除帖子用例
class LifeDelTopicUsecase {
  final LifeRepository _repository;

  const LifeDelTopicUsecase(this._repository);

  Future<void> execute({required String id}) async {
    try {
      await _repository.delTopic(id: id);
    } on BusinessException {
      rethrow;
    } catch (e, st) {
      Log.e('LifeDelTopicUsecase 失败', e.toString(), st);
      throw Exception('删除帖子失败');
    }
  }
}

final lifeDelTopicUsecaseProvider = Provider(
  (ref) => LifeDelTopicUsecase(ref.read(lifeRepository)),
);
